﻿Public Class frmAdvertPhone
    Public file_name As String
    Public phones() As String


    Private Sub frmAdvertPhone_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        If file_name <> "" Then
            picPhone.Visible = True
            picPhone.Image = Drawing.Image.FromFile( _
                Application.StartupPath & "\Resources\Tesseract\" & file_name _
            )
            txtPhone.Location = New System.Drawing.Point(10, 100)
        Else
            picPhone.Visible = False
            txtPhone.Location = New System.Drawing.Point(10, 40)
            txtPhone.Size = New System.Drawing.Size(270, 130)
        End If
        txtPhone.Focus()
        My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Hand)
    End Sub


    Private Sub frmAdvertPhone_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If e.CloseReason = CloseReason.UserClosing Then
            e.Cancel = True
            Exit Sub
        End If
        If file_name <> "" Then
            picPhone.Image.Dispose()
        End If
    End Sub


    Private Sub btnOk_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOk.Click
        Dim ret As New ArrayList
        Dim value As String = txtPhone.Text
        Dim phone As Object

        'Обрабатываем номера телефонов и проверяем их
        value = value.Trim()
        If value = "" Then Exit Sub
        value = Regex.Replace(value, vbCr, vbLf)
        value = Regex.Replace(value, vbLf & vbLf, vbLf)
        For Each phone In Split(value, vbLf)
            phone = phone.Trim()
            If phone = "" Then Continue For
            phone = getBigPhone(phone)
            If Equals(phone, False) = True Then
                MsgBox("Некоторые выражения не являются телефонами." & vbNewLine & "Проверьте правильность ввода.", MsgBoxStyle.Exclamation)
                Exit Sub
            End If
            ret.Add(phone)
        Next

        'Если сюда дошли, значит все номера нормальные
        'Заносим массив нормальных телефонов в текстовое поле и выходим из формы
        phones = ret.ToArray(System.Type.GetType("System.String"))
        Me.Hide()
    End Sub
End Class